
#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

const wregex mcWregexEnDate(L"[a-zA-Z]+ \\d+, \\d+");

const vector<string> mcVecStrEnMonth = {
	"january", "february", "march", "april",
	"may", "june", "july", "august",
	"september", "october", "november", "december"
};

void TextNormalizer::TnReEnDate(wstring* fpInWsentence, const LanguageEnum fcInLanguage)
{
	wsmatch tWsmatch;

	while( regex_search(*fpInWsentence, tWsmatch, mcWregexEnDate) )
	{
		string tStrEnDate = wstring2utf8string(tWsmatch[0]);		//匹配到的字符串
		
		StrReplace(tStrEnDate, ",", "");

		vector<string> tVecEnDate = StrSplit(tStrEnDate, " ");
		string tStrMonth = tVecEnDate[0];
		string tStrDay = tVecEnDate[1];
		string tStrYear = tVecEnDate[2];

		string tStrReplace = "";

		transform(tStrMonth.begin(), tStrMonth.end(), tStrMonth.begin(), ::tolower);		//大写转小写

		if( mcVecStrEnMonth.end() != find(mcVecStrEnMonth.begin(), mcVecStrEnMonth.end(), tStrMonth)
			&& IsStrAllNumber(tStrDay) && IsStrAllNumber(tStrYear)
		) {
			tStrReplace += tStrMonth;
			tStrReplace += " ";
			tStrReplace += ReplaceMethod(vector<string>{tStrDay}, RME_en_ordinal_number);
			tStrReplace += "，";

			if(tStrYear.length() == 4) {
				tStrReplace += ReplaceMethod(vector<string>{tStrYear}, RME_en_year);
			}
			else {
				tStrReplace += ReplaceMethod(vector<string>{tStrYear}, RME_en_negative_decimal);
			}
			tStrReplace += " ";
		}
		else {
			tStrReplace = tStrMonth + "   " + tStrDay + " , " + tStrYear;
		}

		WstrReplacePosition(fpInWsentence, tWsmatch.position(0), tWsmatch.length(0), utf8string2wstring(tStrReplace));
	}
}
